<%--
 *  File:    DBArchive.jsp
 *  @Author: Jamesli
 *  Date:    2010/09/06
 *
 *  Copyright (C) 2000 - 2010 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>

<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>
<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.DBArchive"); 

  //init param
  String strTableName = "v_archivectrl";
  String strModuleName = "IMG";
  String privilegeCode = "E0211";
  String contextPath = request.getContextPath();
%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title>DBArchive</title>
<PageFlow:CheckPageFlow pageName="p_dbarcsummary"/>
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<script>
function page_checkall(){
	var allcheck = cform.checkall;
	var alltable = document.getElementsByName("deltname");
	for(var i = 0 ; i < alltable.length;i++){
		alltable[i].checked = allcheck.checked;
	}
}

function page_uncheckall(element){
	if(!element.checked)cform.checkall.checked = false;
}

function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  editform.action = "DBArchive.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}
  
 function showview(element){ 
	 var x,y; 
	 x = event.clientX; 
	 y = event.clientY; 
	 document.getElementById("floatview").style.left = x; 
	 document.getElementById("floatview").style.top = y; 
	 document.getElementById("floatview").innerHTML = element.value.replace(/</,"&#60");
	 if(element.value.length > 17){ 
	 	document.getElementById("floatview").style.display = "block";
	 } 
 } 
 function hiddenview(){
	 if(document.getElementById("floatview").style.display == "block"){
		 document.getElementById("floatview").innerHTML = ""; 
		 document.getElementById("floatview").style.display = "none";
	 } 
 }

 function page_checkseqno(element){
	var elementName = element.name;
	var seqno = eval('cform.' + elementName + '.value');
	var excludetname = eval('cform.' + elementName.replace(/seqno/, "tname") + '.value');
	if(seqno == ""){
		if(elementName == "seqno"){
			return;
		}else{
			page_oldseqno(elementName);
			return;
		}
	}
	cform.checkcount.value = "";
	var datahandler = new  DataHandler() ;
	datahandler.add_params("seqno" , seqno, 'String');
	datahandler.add_params("excludetname" , excludetname, 'String');
	datahandler.getResult("countnum" ,"document.cform.checkcount");
	datahandler.add_job("j_allcheck");
	datahandler.add_function("page_checkresult('seqno','" + elementName + "')");
	datahandler.runDataHandler();
 }
 
 function page_checktname(){
	var tname = cform.tname.value;
	if(tname == "")return;
	cform.checkcount.value = "";
	var datahandler = new  DataHandler() ;
	datahandler.add_params("tname" , tname, 'String');
	datahandler.getResult("countnum" ,"document.cform.checkcount");
	datahandler.getResult("tnamepk" ,"document.cform.tnamepk");
	datahandler.add_job("j_allcheck");
	datahandler.add_function("page_checkresult('tname')");
	datahandler.runDataHandler();
 }

 function page_checkparenttname(){
	var parenttname = cform.parenttname.value;
	if(parenttname == ""){
		page_conditionnbsp();
		return;
	}
	cform.checkcount.value = "";
	var datahandler = new  DataHandler() ;
	datahandler.add_params("parenttname" , parenttname, 'String');
	datahandler.getResult("countnum" ,"document.cform.checkcount");
	datahandler.add_job("j_allcheck");
	datahandler.add_function("page_checkresult('parenttname')");
	datahandler.runDataHandler();
 }

 function page_checkarctotname(){
	var arctotname = cform.arctotname.value;
	if(arctotname == "")return;
	cform.checkcount.value = "";
	var datahandler = new  DataHandler() ;
	datahandler.add_params("arctotname" , arctotname, 'String');
	datahandler.getResult("countnum" ,"document.cform.checkcount");
	datahandler.add_job("j_allcheck");
	datahandler.add_function("page_checkresult('arctotname')");
	datahandler.runDataHandler();
 }

 function page_checktnamerk(){
	var tnamerk = cform.tnamerk.value;
	if(tnamerk == ""){
		page_conditionnbsp();
		return;
	}
	var tname = cform.tname.value;
	var tnamepk = cform.tnamepk.value;
	if(tname == "" || tnamepk == ""){
		alert("<%= message.getMessageDesc("P_0054",label.getLabelName("L_ArchiveTable")) %>");
		cform.tname.focus();
		return;
	}
	cform.checkcount.value = "";
	var datahandler = new  DataHandler() ;
	datahandler.add_params("tnamerk" , tnamerk, 'String');
	datahandler.add_params("tname" , tname, 'String');
	datahandler.add_params("tnamepk" , tnamepk, 'String');
	datahandler.getResult("countnum" ,"document.cform.checkcount");
	datahandler.add_job("j_allcheck");
	datahandler.add_function("page_checkresult('tnamerk')");
	datahandler.runDataHandler();
 }

 function page_oldseqno(elementName){
	var thetname = eval('cform.' + elementName.replace(/seqno/, "tname") + '.value');
	var datahandler = new  DataHandler() ;
	datahandler.add_params("thetname" , thetname, 'String');
	datahandler.getResult("oldseqno" ,"document.cform." + elementName);
	datahandler.add_job("j_allcheck");
	datahandler.runDataHandler();
 }
 
 function page_checkresult(type,elementName){
	var resultcount = cform.checkcount.value;
	if(type == "tname"){
		if(resultcount != 1){
			if(resultcount == -1){
				alert("<%= message.getMessageDesc("A_ALREADY_EXISTS",label.getLabelName("L_ArchiveTable")) %>");
				cform.tnamepk.value = "";
			}
			cform.tname.value = "";
			cform.tname.focus();
		}
	}else if(type == "parenttname"){
		if(resultcount != 1){
			alert("<%= message.getMessageDesc("A_NOT_CORRECT",label.getLabelName("L_ParentTable")) %>");
			cform.parenttname.value = "";
			cform.parenttname.focus();
		}else{
			page_conditionnbsp();
		}
	}else if(type == "arctotname"){
		if(resultcount != 1){
			alert("<%= message.getMessageDesc("A_NOT_CORRECT",label.getLabelName("L_Archive2Table")) %>");
			cform.arctotname.value = "";
			cform.arctotname.focus();
		}
	}else if(type == "tnamerk"){
		if(resultcount != 1){
			alert("<%= message.getMessageDesc("A_NOT_CORRECT",label.getLabelName("L_ArchiveTableRK")) %>");
			cform.tnamerk.value = "";
			cform.tnamerk.focus();
		}else{
			page_conditionnbsp();
		}
	}else if(type == "seqno"){
		if(resultcount != 0){
			alert("<%= message.getMessageDesc("A_ALREADY_EXISTS",label.getLabelName("L_SeqNo")) %>");
			var element = eval("cform." + elementName);
			element.focus();
			element.value = "";
		}
	}
 }

 function page_conditionnbsp(){
	var parenttname = cform.parenttname.value;
	var tnamerk = cform.tnamerk.value;
	var arccondition = document.getElementById("arccondition");
	var arcconditiondesc = document.getElementById("arcconditiondesc");
	if(parenttname != "" || tnamerk != ""){
		if(arccondition.innerHTML != "&nbsp;"){
			arccondition.innerHTML = "&nbsp;";
		}
		if(arcconditiondesc.innerHTML != "&nbsp;"){
			arcconditiondesc.innerHTML = "&nbsp;";
		}
	}else{
		if(arccondition.innerHTML == "&nbsp;"){
			arccondition.innerHTML = '<input type="text" name="arccondition"/>';
		}
		if(arcconditiondesc.innerHTML == "&nbsp;"){
			arcconditiondesc.innerHTML = '<input type="text" name="arcconditiondesc"/>';
		}
	}
 }
 
 function page_add(){
	if(!checkForm(cform))return;
	if((cform.parenttname.value == "" && cform.tnamerk.value != "") || (cform.parenttname.value != "" && cform.tnamerk.value == "")){
		alert("<%= message.getMessageDesc("A_B_MUST_EXISTS_OR_NOT_SAME_TIME",label.getLabelName("L_ParentTable"),label.getLabelName("L_ArchiveTableRK")) %>");
		return;
	}
	cform.parenttname.value = cform.parenttname.value.toUpperCase();
	cform.tname.value = cform.tname.value.toUpperCase();
	cform.tnamepk.value = cform.tnamepk.value.toUpperCase();
	cform.arctotname.value = cform.arctotname.value.toUpperCase();
	cform.tnamerk.value = cform.tnamerk.value.toUpperCase();
	cform.target = "_self";
	document.cform.actionname.value = "add";
	isRunning = true;
	document.cform.submit();
 }

 function page_delete(){
	var alltname = document.getElementsByName("deltname");
	var checkflag = false;
	for(var i = 0 ; i < alltname.length;i++){
		if(alltname[i].checked){
			var selectElement = eval('cform.enableflag' + i);
			var enableflag = selectElement.options[selectElement.selectedIndex].value;
			if(enableflag == "Y"){
				alert("<%= message.getMessageDesc("CANT_DELETE_ENABLED_RECORD") %>");
				return;
			}
			checkflag = true;
		}
	}
	if(!checkflag){
		alert("<%= message.getMessageDesc("PLEASE_SELECT")%>");
		return;
	}
	if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>")) return;
	
	cform.target = "_self";
	document.cform.actionname.value = "delete";
	isRunning = true;
	document.cform.submit();
 }

 function page_save(){
	var t = null;
	if(top.topFrame != null)
	  t = top.topFrame;
	if(t != null)
	  message = t.message;
	else
	  message = new ActiveXObject("Scripting.Dictionary");
	for(var i=0;i < cform.numrows.value;i++)
	{
	  var elem = eval("cform.seqno" + i);
	  if(!checkCommand(elem))
	    return;
	  if(!checkLength(elem))
	    return;
	}
	
	if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_SAVE") %>")) return;
	cform.updateinsertflag.value = "update";
	cform.target = "_self";
	document.cform.actionname.value = "save";
	isRunning = true;
	document.cform.submit();
 }

 var popwindow;
 function page_addchoosen(){
	if(popwindow!=null) popwindow.close();
	popwindow = window.open("<%=contextPath%>/db/dbarc/DBArchiveObjects.jsp?<%= OvalTools.randomURL() %>", "newwindow", "height=600, width=1100,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=yes");
 }

 function page_textpop(targetname){
	if(popwindow!=null) popwindow.close();
	popwindow = window.open("<%=contextPath%>/db/dbarc/TextPop4DBArchive.jsp?<%= OvalTools.randomURL() %>&target=" + targetname, "newwindow", "height=300, width=800,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
 }
</script>
</head>
<body>
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
<div id="floatview" style="display:none;position:absolute;z-index:1;background:#fdfddf;border:#cccccc 1px solid;"></div>
<% //--------------------------------------  page location --%>
	<%@ include file="/inc/PageLocation.inc" %>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
<form name="cform" method="post" action="<%=contextPath %>/Dispatcher"  target="_self">
	<input type="hidden" name="pagename" value="p_dbarcsummary">
	<input type="hidden" name="actionname">
	<input type="hidden" name="checkcount">
	<input type="hidden" name="updateinsertflag">
   <tr>
    <td> 
      <table width="100%" border="0" cellspacing="0">
      	  <tr>
          	<td class="summary_top" width="10%" colspan="3"></td>
          </tr>
          <%@ include file="/inc/SummarySearch.inc" %>
      </table>
    </td>
  </tr>
  <tr> 
    <td class="td_center"> 
      <table width="1500" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
         <tr  class="deepblue-left"> 
            <td width="4%" class="title_center"><custom:checkbox property="checkall" styleClass="checkbox" onclick="page_checkall()"/></td>
            <td width="6%" class="title_center"><%= label.getLabelName("L_SeqNo") %></td>
            <td width="6%" class="title_center"><%= label.getLabelName("L_ParentTable") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_ArchiveTable") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_ArchiveTablePK") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_Archive2Table") %></td>
            <td width="6%" class="title_center"><%= label.getLabelName("L_ArchiveTableRK") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_ArchiveCondition") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_ArchiveConditionDesc") %></td>
            <td width="6%" class="title_center"><%= label.getLabelName("L_ArchiveCycle") %></td>
            <td width="6%" class="title_center"><%= label.getLabelName("L_LastArchiveDate") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_LastArchiveMsg") %></td>
            <td width="6%" class="title_center"><%= label.getLabelName("L_ValidOrNot") %></td>
         </tr>
         <%
             int j = 0;
             String strClassType = new String(); 
             Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
             if(totalsummary == null) totalsummary = new Vector();
          %>
          <logic:iterate id="summary" collection="<%= totalsummary %>">                      
         <%
            HashMap summaryMap = (HashMap)pageContext.getAttribute("summary");
            if(summaryMap == null) summaryMap = new HashMap();
            String strIsChecked = new String("");
            
            if(j%2 == 1){
              strClassType = "td-listrom";             
            }else{                    
              strClassType = "";
            }
              

          %>
           <tr onmouseover="this.className='tr-over'" onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'" class="<%=JspHelper.filterNull(strClassType)%>">
            <td class="title_center"><custom:checkbox property="tname" name="summary" styleClass="checkbox" changedName="deltname" onclick="page_uncheckall(this)"/></td>
            <custom:hidden property="tname" name="summary" colIndex="<%=new Integer(j) %>"/>
            <td><custom:text property="seqno" name="summary" command="notnull" label="L_SeqNo" maxlength="10" size="2" colIndex="<%=new Integer(j) %>" onchange="page_checkseqno(this)"/></td>
            <td><custom:write property="parenttname" name="summary" nbsp="true"/></td>
            <td><custom:write property="tname" name="summary" nbsp="true"/></td>
            <td><custom:write property="tnamepk" name="summary" nbsp="true"/></td>
            <td><custom:write property="arctotname" name="summary" nbsp="true"/></td>
            <td><custom:write property="tnamerk" name="summary" nbsp="true"/></td>
            <td>
            	<%if(summaryMap.get("parenttname") == null || ((summaryMap.get("parenttname")).equals(""))){ %>
            	<custom:text property="arccondition" name="summary" onmouseover="showview(this)" onmouseout="hiddenview()" colIndex="<%=new Integer(j) %>" maxlength="2000"/><A onclick="page_textpop('arccondition<%=j %>')"><custom:button type="1" label="L_Dots" border="0" style="width:15"/></A>
            	<%}else{ %>
            	&nbsp;
            	<%} %>
            </td>
            <td>
            	<%if(summaryMap.get("parenttname") == null || ((summaryMap.get("parenttname")).equals(""))){ %>
            	<custom:text property="arcconditiondesc" name="summary" onmouseover="showview(this)" onmouseout="hiddenview()" colIndex="<%=new Integer(j) %>" maxlength="500"/><A onclick="page_textpop('arcconditiondesc<%=j %>')"><custom:button type="1" label="L_Dots" border="0" style="width:15"/></A>
            	<%}else{ %>
            	&nbsp;
            	<%} %>
            </td>
            <td><custom:write property="arcmonthcnt" name="summary" nbsp="true"/></td>
            <td class="td_center"><custom:write property="lastarctime" name="summary" nbsp="true"/></td>
            <td><custom:write property="lastarcmsg" name="summary" nbsp="true"/></td>
            <td><select name="enableflag<%=j %>">
            <%String enableflag = (String)summaryMap.get("enableflag"); %>
            		<option value="Y" <%=enableflag.equalsIgnoreCase("Y")?"selected":"" %>><%=label.getLabelName("L_Yes") %></option>
            		<option value="N" <%=enableflag.equalsIgnoreCase("N")?"selected":""%>><%=label.getLabelName("L_No") %></option>
            	</select>
            </td>
          </tr>
          <%
          	j++;      
          %>
          </logic:iterate>
          <custom:hidden property="numrows" value="<%=j+"" %>"/>
          <tr>
            <td>&nbsp;</td>
            <td><custom:text property="seqno" onchange="page_checkseqno(this)" command="notnull" label="L_SeqNo" size="2" maxlength="10"></custom:text></td>
            <td><custom:text property="parenttname" onchange="page_checkparenttname()"></custom:text></td>
            <td><custom:text property="tname" onchange="page_checktname()" command="notnull" label="L_ArchiveTable"></custom:text></td>
            <td><input type="text" name="tnamepk" readonly="readonly" style="border:0px"/></td>
            <td><custom:text property="arctotname" onchange="page_checkarctotname()" size="25" command="notnull" label="L_Archive2Table"></custom:text></td>
            <td><input type="text" name="tnamerk" onchange="page_checktnamerk()"/></td>
            <td id="arccondition"><input type="text" name="arccondition" maxlength="2000"/><A onclick="page_textpop('arccondition')"><custom:button type="1" label="L_Dots" border="0" style="width:15"/></A></td>
            <td id="arcconditiondesc"><input type="text" name="arcconditiondesc" maxlength="500"/><A onclick="page_textpop('arcconditiondesc')"><custom:button type="1" label="L_Dots" border="0" style="width:15"/></A></td>
            <td><custom:text property="arcmonthcnt" dataType="integer" label="L_ArchiveCycle" maxlength="2" size="1"></custom:text></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td><select name="enableflag">
            		<option value="Y"><%=label.getLabelName("L_Yes") %></option>
            		<option value="N" selected="selected"><%=label.getLabelName("L_No") %></option>
            	</select>
            </td>
          </tr>
      <% //--------------------------------------  flipping page --%>
      <%@ include file="/inc/SummaryAction.inc" %>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr> 
          <td class="summary_top"></td>
        </tr>
        <tr> 
          <td class="td_center">
          	<a onclick="page_add()"><custom:button type="1" label="L_Add" imgsrc="edit.gif" border="0" style="width:80"/></a>
          	<a onclick="page_addchoosen()"><custom:button type="1" label="L_AddChoosen" imgsrc="edit.gif" border="0" style="width:80"/></a>
          	<%if(j > 0){ %>
          	<a onclick="page_save()"><custom:button type="1" label="L_Save" imgsrc="edit.gif" border="0" style="width:80"/></a>
            <a onclick="page_delete()"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:100"/></a>
            <%} %>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  </form>
</table>
</body>
</html>